package scala.demo

import scala.collection.immutable.HashMap


//每瓶啤酒2元，3个空酒瓶或者5个瓶盖可换1瓶啤酒。100元最多可喝多少瓶啤酒？
object HelloWord {
  var totals=0


  def main(args: Array[String]): Unit = {
    var money=100
    var beer=2

    var nullBottle=3
    var cap=5

    var start=init(money,beer)

    bottleNum(start,0,0)
     println("啤酒总数是"+totals)

  }

  def bottleNum(start:Int,leftBottle:Int,leftCap:Int):HashMap[String, Int]={
    var sum:Int=start
    totals+=sum
    if(leftBottle!=0&&leftCap!=0){
      if ((start+leftBottle) < 3 && (start+leftCap) < 5) return  null
    }

    val hashMap = HashMap("beer"->((start+leftBottle)/3+(start+leftCap)/5), "leftBottle"->start%3, "leftCap"->start%5)

    bottleNum(hashMap.get("beer").get,hashMap.get("leftBottle").get,hashMap.get("leftCap").get)
  }

  def init(money:Int,beer:Int):Int={
    var sum:Int=0
    sum=money/beer
    sum

  }

}
